/**
 * 问题列表
 */
import query from '../../untils/mysql';
import { Tip } from '../../untils/untils';
import { check, validationResult } from 'express-validator';

const validator = [
    check('id').notEmpty().withMessage("问题id不能为空！")
]

const GET = async (req: any, res: any, next: any) => {
    try {
        var errors = validationResult(req);
        if (!errors.isEmpty()) {
            return Tip.tipError(res, errors.array()[0].msg);
        }
        const { id } = req.query;
        const sql = `select 
            a.*,
            b.name userName,
            b.name handlerName,
            b.name sendName,
            c.name projectName from problem a 
            left join user b on (a.user_id = b.id and a.handlerId = b.id and a.sendId = b.id ) 
            left join project c on a.project_id = c.id 
            where a.id = '${id}'`
        const data = await query(sql);
        if (data.length === 0) {
            return Tip.tipError(res, "id找不对对应的问题记录")
        }
        return Tip.tipSuccess(res, '查询成功', data[0])
    } catch (error: any) {
        Tip.tipError500(res, error)
    }
}

export {
    GET,
    validator
}